<template>
  <div style="padding-bottom: 42px;">
    <div class="search-block" v-if="showsearch">
      <searchtab @searchopen="opensearch" @checkstab="goindex" @linksearch="searchlink" :tablist="tablistprop"></searchtab>
    </div>
    <div class="search-block-new" v-if="showsearchlist">
      <searchlist @cansearch="searchcan" :searchprop="searchtext"></searchlist>
    </div>
    <div class="login-bloock" v-if="showlogin">
      <loginpop @bindlogin="loginbloock"></loginpop>
    </div>
    <div class="detail-top-tab pc-bk" >
      <navblock></navblock>
    </div>
    <div class="top-content-block" v-if="loginuser">
      <div class="left-nav pc-bk" ref="leftnav" v-bind:class="{'scroll':scrolldetail === 1, 'fbottom':fixedbottom === 1}" ><!--左侧导航-->
        <div class="side-header hy">
          <span class="sidle-text">{{first_level_cname}}
          <!-- <i>BRAINPOWER</i> -->
          </span>
          <span class="sidle-icon"><img src="../../img/mobile/side-header-hy.jpg"></span>
        </div>
        <div class="meeting-list  detail-sidle">
          <ul>
            <li v-for="(meetlist, index) in tablist" v-if="meetlist.item_id !== 0" v-bind:class="{'open': meetlist.is_selected === 1}"  @click="linktoUser" :data-key="meetlist.key">
              <div class="detail-sidle-main" @click="moreBtn" :data-id="meetlist.id" :data-itid="meetlist.item_id" :data-type="meetlist.content_type">
                <span class="focus-icon">
                </span>
                <span class="focus-title-link">
                  {{meetlist.name}}
                </span>
              </div>
            </li>
          </ul>
        </div>
      </div>
      <div class="listpage-content"  v-bind:class="{'scroll':scrolldetail === 1}" >
        <div class="top-line-title">
          <div class="side-header light-user pc-bk">
            <span class="sidle-text">{{thistitle}}</span>
            <span class="sidle-icon"><img src="../../img/mobile/side-header-light.jpg"></span>
          </div>
          <div class="detail-search">
            <input type="text"  v-model="searchtext" placeholder="全站搜索 Search" @keyup.enter="searchBtn1">
            <img src="../../img/mobile/search_new.png"  @click="searchBtn1">
          </div>
        </div>
        <div class="content-list-block">
          <div class="content-list-body list down-list-block">
            <!-- <div class="agenda-list pc-bk">

            </div> -->
            <div class="down-article-list" v-for="downlist in downlist">
              <div class="article-list-top">
                <div class="article-list-title">
                  <span class="left-tt-note">
                    标题
                  </span>
                  <span class="list-title-text">
                    {{downlist.title}}
                  </span>
                </div>
                <div class="down-btn" @click="DownFile" :data-url="downlist.attach">
                  下载
                </div>
              </div>
              <div class="article-list-content">
                {{downlist.note}}
              </div>
            </div>
            <div class="list-page pc-bk">
              <el-pagination
                  @current-change="handleCurrentChange"
                  background
                  layout="prev, pager, next"
                  :total="total"
              >
              </el-pagination>
            </div>
          </div>
        </div>
      </div>
      <!-- <div class="no-content" v-bind:class="{'scroll':scrolldetail === 1}"  v-else>
        <div class="nosearch">
          <img src="../../img/mobile/emptycontent.jpeg" alt="">
        </div> -->
        <!-- 空空如也！ -->
      <!-- </div> -->
      <footernav></footernav>
    </div>
    <div class="no-content loginfirst" v-else>
      请登录后查看下载中心，请先 <span @click="openLogin">登录</span>
    </div>
  </div>
</template>
<script>
  import api from '../../utils/api'
  import apiConfig from '../../utils/apiconfig.js'
  import helper from '../../utils/helper'
  import navblock from './components/nav'
  import searchtab from './components/searchtab'
  import searchlist from './components/search'
  import footernav from './components/footernav'
  import loginpop from './components/login'
  import { Indicator, Spinner, MessageBox } from 'mint-ui'
  export default {
    data () {
      return {
        downlist: [],
        data: {
          list: []
        },
        showlogin: false,
        loginuser: true,
        ismail: false,
        form: {
          nkname: '',
          sex: '',
          marry: ''
        },
        scrolldetail: 0,
        searchtext: '',
        page: 1,
        total: 0,
        limtsize: 9,
        tablist: [],
        showsearchlist: false,
        // pages: 1,
        loading: false,
        showmore: true,
        imgUrl: '',
        secondlist: [],
        first_level_cname: '关于我们',
        articlelist: [],
        thistitle: '',
        thisid: 0,
        checkAll: false,
        checkedArticle: [],
        cities: [],
        isIndeterminate: true
      }
    },
    components: {
      navblock,
      searchtab,
      searchlist,
      footernav,
      loginpop
    },
    mounted () {
      window.addEventListener('scroll', this.handleScroll)
    },
    created () {
      var that = this
      this.logintoken = localStorage.token
      if (localStorage.token && localStorage.token !== '') {
        this.getdownlist(1)
      } else {
        this.loginuser = false
        this.showlogin = true
        // this.getArticlelist(1)
      }
    },
    methods: {
      DownFile (e) {
        var that = this
        var downurl = e.currentTarget.dataset.url
        window.open(downurl)
      },
      loginbloock (val) {
        this.showlogin = val
      },
      openLogin () {
        this.showlogin = true
      },
      getdownlist (page) {
        var that = this
        this.page = page
        var param = {
          token: this.logintoken,
          page: page
        }
        console.log(param)
        Indicator.open('加载中...')
        this.params = param
        api.GET(helper.getClientApiUrl(apiConfig.web.downloadlist), this.params, res => {
          // that.articlelist = res.data.list
          // that.data.list = res.list
          that.tablist = res.nav
          that.tablist.forEach((item, index) => {
            if (item.is_selected === 1) {
              that.thistitle = item.name
              that.thisid = item.id
            }
          })
          that.first_level_cname = res.nav_title
          that.total = res.list.length
          that.downlist = res.list
          console.log(res)
          Indicator.close()
        }, res => {
          console.log(res)
          Indicator.close()
        })
      },
      handleScroll () {
        var scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop
        if (scrollTop >= 100) {
          this.scrolldetail = 1
        } else {
          this.scrolldetail = 0
        }
      },
      searchBtn1 () {
        this.showsearchlist = true
      },
      opensearch (val) {
        console.log('test:' + val)
        this.showsearch = val
      },
      searchlink (val) {
        console.log('testsss:' + val)
        this.showsearchlist = val
      },
      searchcan (val) {
        this.showsearchlist = val
      },
      moreBtn (e) {
        console.log(e.currentTarget.dataset.type)
        let conttype = e.currentTarget.dataset.type
        if (conttype === 'AUTHOR') {
          this.$router.push('/home/authorlist?id=' + e.currentTarget.dataset.id)
        } else if (conttype === 'news_detail') {
          this.$router.push('/home/detail?id=' + e.currentTarget.dataset.id)
        } else {
          this.getDatalist(e.currentTarget.dataset.id, 1)
          this.$router.push('/home/list?id=' + e.currentTarget.dataset.id)
          this.tabid = e.currentTarget.dataset.id
        }
        // this.$router.push('/home/list?id=' + e.currentTarget.dataset.id)
        // window.location.reload()
      },
      linktoUser (e) {
        var that = this
        console.log('111')
        var thiskey = e.currentTarget.dataset.key
        if (thiskey === 'USER_CENTER') {
          that.$router.push('/home/userpage?id=' + 1)
          that.thisid = 1
          that.getuserInfo()
        } else if (thiskey === 'USER_FAVOURITE') {
          that.$router.push('/home/userpage?id=' + 2)
          that.thisid = 2
          that.getArticlelist(1)
        } else if (thiskey === 'DOWNLOAD') {
          that.$router.push('/home/downlist')
        }
      }
      // handleCurrentChange (val) {
      //   this.getDatalist(this.tabid, val)
      // },
    }
  }
</script>
